extends NodeState


@export var enemy: BasicEnemy


# 最后一次攻击时间
var last_attack_time: float = 0.0

var remote_attack_location: Vector2 = Vector2.ZERO


func _on_process(_delta : float) -> void:
	enemy.look_at_player()
	process_throw_knife()



func _on_next_transitions() -> void:
	pass


func _on_enter() -> void:
	remote_attack_location = Vector2.ZERO
	enemy.animationPlayer.play(BasicEnemy.ANIMATION_IDLE)


func _on_exit() -> void:
	pass



func process_throw_knife():
	if Time.get_ticks_msec() - last_attack_time < enemy.duration_between_hits:
		return

	# 如果射线检测到碰撞，说明可以投掷小刀
	if enemy.projectileAim.is_colliding():
		last_attack_time = Time.get_ticks_msec()
		enemy.animationPlayer.play(BasicEnemy.ANIMATION_THROW)
		return

	transition_state(BasicEnemy.STATE_IDLE)



func on_throw_animation_finished():
	enemy.throw_weapon(Collectible.Type.KNIFE)
	enemy.throws_knife()
	transition_state(BasicEnemy.STATE_IDLE)
